#include "TrtEngine.h"
#include <assert.h>
#include <memory>

#include <opencv2/opencv.hpp>
#include <opencv2/hdf.hpp>

#include <cuda_runtime_api.h>
#include <NvInfer.h>
#include <memory>
#include <NvOnnxParser.h>
#include <vector>
#include <numeric>
#include <chrono>
#include "yolov5.h"
#include "timer.hpp"
#define CHECK(status)                              \
    do                                             \
    {                                              \
        cudaError_t err = (status);                \
        if (err != cudaSuccess)                    \
        {                                          \
            fprintf(stderr, "API error"            \
                            "%s:%d Returned:%d\n", \
                    __FILE__, __LINE__, err);      \
            exit(1);                               \
        }                                          \
    } while (0)

void matp(cv::Mat mat)
{
    printf("mat.step[0]=%ld\n", mat.step[0]);                                                //每一行所占字节数目
    printf("mat.step[1]=%ld\n", mat.step[1]);                                                //每个元素所占字节数
    cout << "L::" << __LINE__ << " size:" << mat.size() << " " << mat.step[0] / (4) << endl; //每个元素所占字节数
}
int main(int argc, char *argv[])
{
    TrtEngine te;
    Yolov5 yolov5;
    const char *onnx = "/project/train/models/n6_zhan.onnx";
    // te.loadOnnxEngine(te.path); //转tensorrt
    te.loadTRTEngine(te.path); //转tensorrt

    string engine = "/project/train/models/n6_zhan.trt";
    string path = "../p1.jpg";
    // te(engine);
    cv::Mat img;
    img = cv::imread(path);
    for (size_t i = 0; i < 1000; i++)
    {
        Timer t("all:");
        auto pdata = te.ProcessImage(img);
        vector<Output> output;
        yolov5.postresult_trt(pdata, img, output, 0.5, 6);
    }
    return 0;
}
